package com.qf.Listener.config;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



/**
 * 通过代码的方式创建 交换机和队列
 */
@Configuration
public class RabbitMqConfig {
    @Bean("queue3")
    public Queue createQueue03(){
        //创建队列对象，并返回
        return new Queue("direct-queue",true,false,false,null);
    }
    @Bean("queue4")
    public Queue createQueue04(){
        //创建队列对象，并返回
        return new Queue("direct1-queue",true,false,false,null);
    }
    //创建路由key连接交换机
    @Bean
    public Binding binding(@Qualifier("queue3") Queue queue, DirectExchange directExchange){
        //绑定队列到交换机
        return BindingBuilder.bind(queue).to(directExchange).with("key");
    }
    @Bean
    public Binding binding4(@Qualifier("queue4") Queue queue, DirectExchange directExchange){
        //绑定队列到交换机
        return BindingBuilder.bind(queue).to(directExchange).with("key1");
    }
    //创建路由交换机
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("boot-direct-exchange",false,false);
    }
//    @Bean("cd")
//    public DirectExchange directExchange1(){
//        return new DirectExchange("boot-direct1-exchange",false,false);
//    }
    //绑定计算机和路由
    @Bean
    public Binding binding1(@Qualifier("queue1") Queue queue, FanoutExchange fanoutExchange){


        //绑定队列到交换机
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }
    @Bean
    public Binding binding2(@Qualifier("queue2") Queue queue, FanoutExchange fanoutExchange){


        //绑定队列到交换机
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }
    //创建交换机
    @Bean
    public FanoutExchange creatExchange(){
        return new FanoutExchange("boot-fanout-exchange",false,false);
    }

    @Bean("queue1")
    public Queue createQueue01(){
        //创建队列对象，并返回
        return new Queue("boot-queue",true,false,false,null);
    }
    @Bean("queue2")
    public Queue createQueue02(){
        //创建队列对象，并返回
        return new Queue("boot-queue1",true,false,false,null);
    }
}
